package output;

import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.util.List;
import java.util.Stack;
import java.util.Vector;

public class Problem3Output implements Output {

	private String outputFile;
	private List<Vector<Integer>> solutions;

	public Problem3Output(List<Vector<Integer>> solutions) {
		this.solutions = solutions;
	}

	public Problem3Output(String fileName) {

		outputFile = fileName;
	}

	@Override
	public void writeFile(String outputFile) throws Exception {
		this.outputFile = outputFile;

		BufferedWriter bufferedWriter = new BufferedWriter(new PrintWriter(
				this.outputFile));

		// Escribimos todas las soluciones.
		for (int i = 0; i < solutions.size(); i++) {

			Vector<Integer> solution = solutions.get(i);
			printSolution(bufferedWriter, solution);
		}

		bufferedWriter.close();

	}

	private void printSolution(BufferedWriter bufferedWriter,
			Vector<Integer> solution) throws Exception {

		int cut;
		if (!solution.isEmpty()) {
			cut = solution.elementAt(0);
			bufferedWriter.write(String.valueOf(cut));
		}

		for (int i = 1; i < solution.size(); i++) {
			bufferedWriter.write(" ");
			cut = solution.elementAt(i);
			bufferedWriter.write(String.valueOf(cut));

		}

		bufferedWriter.flush();
		bufferedWriter.newLine();

	}

}
